home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 316 / libsrc / alloca.s < prev    next >
Encoding:
Text File  |  1988-10-20  |  918 b   |  46 lines

  1. #NO_APP
  2. |
  3. | alloca(nbytes) allocate junk in stack frame
  4. |
  5.  
  6.     .text
  7. |adbg1:
  8. |    .ascii "alloca(%d)\n\0"
  9. |adbg2:
  10. |    .ascii "->%lx\n\0"
  11. |    .even
  12.  
  13. .globl    _alloca
  14. _alloca:
  15.     movel    sp@+,d1        | get return addr
  16.     movel    sp@,d0        | get size
  17.  
  18. |    movel    d1,sp@-        | save it
  19. |    movel   d0,sp@-
  20. |    pea    adbg1
  21. |    jsr    _printf
  22. |    addql    #4,sp        | pop the string
  23. |    movel    sp@+,d0
  24. |    movel    sp@+,d1
  25.  
  26.     addql    #1,d0        | ensure address even
  27.     andl    #0xFFFFFFFE,d0    | lop off extra bits
  28. |    addql    #8,d0        | slush -- probably not necessary
  29.  
  30.     subl    d0,sp        | increase stack frame size by that much
  31.     movel    sp,d0        | set up to return it
  32.     addql    #4,d0        | add 4 to point past where stack will be
  33.                 |  when we return.  effectively skips the
  34.                 |  size arg
  35.  
  36. |    movel    d1,sp@-
  37. |    movel    d0,sp@-
  38. |    pea    adbg2
  39. |    jsr    _printf
  40. |    addql    #4,sp        | pop the string
  41. |    movel    sp@+,d0
  42. |    movel    sp@+,d1
  43.  
  44.     movel    d1,sp@-        | push ret addr
  45.     rts            | and go there
  46.